/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.cardarus.operatingsystem.struts.actions;

import com.cardarus.operatingsystem.model.BusinessModel;
import com.cardarus.operatingsystem.struts.forms.StockForm;
import com.cardarus.operatingsystem.domain.Item;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 * Gets stock items from model and displays for user
 * @author bryan.hyde
 */
public class StockAction extends org.apache.struts.action.Action {
    /**
     * Gets stock items from model and displays for user
    * @param mapping
     * @param form
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        ActionErrors errors = new ActionErrors();
        HttpSession session = request.getSession();
        BusinessModel model = BusinessModel.getInstance();
        List<Item> stock = model.getStock();
        session.setAttribute("stock", stock);

        return mapping.findForward("success");
    }
}
